//https://leetcode.cn/problems/shan-chu-lian-biao-de-jie-dian-lcof/?envType=study-plan&id=lcof&plan=lcof&plan_progress=jp9wi1h
class Solution {
public:
    ListNode* deleteNode(ListNode* head, int val) {
        ListNode* cur = head;
        ListNode* prev = nullptr;

        while (cur)
        {
            if (cur->val == val)
            {
                if (prev == nullptr)
                {
                    prev = cur->next;
                    head = prev;
                }
                else
                {
                    prev->next = cur->next;
                }
                break;
            }

            prev = cur;
            cur = cur->next;
        }

        return head;
    }
};